package com.binfenhulian.chinaenergy.ces.manage.service.imports;

import com.binfenhulian.chinaenergy.ces.core.bean.enums.ExceptionDescEnum;
import com.binfenhulian.chinaenergy.ces.core.exception.BaseException;
import com.binfenhulian.chinaenergy.ces.manage.core.db.dao.auto.ImportLogDAO;
import com.binfenhulian.chinaenergy.ces.manage.core.db.dao.def.ImportLogDefDAO;
import com.binfenhulian.chinaenergy.ces.manage.core.db.enums.LogStatusEnum;
import com.binfenhulian.chinaenergy.ces.manage.core.db.po.auto.ImportLogPO;
import com.binfenhulian.chinaenergy.ces.utils.date.UnixTimestampUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by wanghjbuf on 2018/3/15.
 */
@Service("com.binfenhulian.chinaenergy.ces.manage.service.imports.ImportServiceImpl")
public class ImportServiceImpl implements ImportService{

    @Autowired
    ImportLogDefDAO importLogDefDAO;
    @Autowired
    ImportLogDAO importLogDAO;

    @Override
    public PageInfo listImportLogByPage(Map<String,Object> paramMap) throws BaseException {
        try {
            Page page = PageHelper.startPage(Integer.parseInt(paramMap.get("pageNum").toString()), Integer.parseInt(paramMap.get("pageSize").toString()));
            PageInfo pageInfo = new PageInfo(importLogDefDAO.query(paramMap));
            return pageInfo;
        } catch (Exception e) {
            throw new BaseException(ExceptionDescEnum.DB.getExceptionDesc(), e);
        }
    }

    @Override
    public int add(String recordNo, String account) throws BaseException {
        try {
            ImportLogPO importLogPO = new ImportLogPO();
            importLogPO.setAccount(account);
            importLogPO.setRecordNo(recordNo);
            importLogPO.setCreateTime(UnixTimestampUtils.currentTimes());
            importLogPO.setStatus(LogStatusEnum.INIT.name());
            return importLogDAO.insertSelective(importLogPO);
        }catch (Exception e){
            throw new BaseException(ExceptionDescEnum.BASE.getExceptionDesc(), e);
        }
    }
}
